\section{Introduction}
\label{sec-introduction}

The \texttt{loop} macro is part of the \commonlisp{} standard
\cite{ansi:common:lisp}, so every conforming \commonlisp{}
implementation contains an implementation of this
macro. \refApp{loop-syntax} contains the part of the syntax of the
\texttt{loop} macro that is relevant for this paper.

The \texttt{loop} macro is frequently criticized as un-Lispy since it
does not use S-expressions for its clauses, and for being impossible
to extend, at least by using only features available in the
\commonlisp{} standard.  In addition, advocates of purely-functional
programming also criticize it, along with all other iteration
constructs that can not be explained in terms of recursion.

Despite all this criticism, the \texttt{loop} macro is an essential
and widely used part of any non-trivial \commonlisp{} program.  It is
able to satisfy the vast majority of iteration needs.  In addition, it
is far easier to understand than equivalent loops using other
iteration constructs such as \texttt{dotimes}, \texttt{dolist}, and
\texttt{do}.

Most current implementations of \commonlisp{} seem to use an
implementation of the \texttt{loop} macro that was largely written
before the \commonlisp{} standard was adopted.  Consequently, some of
the interesting features of the standardized \commonlisp{} language
are not used in the implementation of the \texttt{loop} macro in
these implementations.  In particular, the use of \emph{generic
  functions} is typically minimal.  As a result, the implementation of
this macro is quite \emph{monolithic}, making it hard to maintain,
whether in order to remove defects or to extend it.

We present a modern implementation of the \texttt{loop} macro.  This
implementation was written as part of the \sicl{} project, of
which one of the explicit goals is to use improved coding techniques.

We are able to obtain a more modular \texttt{loop} implementation by
using two key techniques.  The first one is to parse the clauses using
a parsing technique that allows for individual clause parsers to be
\emph{textually separated} according to clause type.  The second
modularity technique is to use \emph{generic functions} for semantic
analysis and code generation.  By defining clause types as standard
classes, we are able to textually separate processing according to
clause type through the use of methods specialized to these clause
classes.
